package PTA_05_29;

public class Main2 {
    public static void main(String[] args) {

        Student2 xiaoxin = new Student2();
        xiaoxin.feedPet(new Dog("小汪"));
        xiaoxin.feedPet(new Cat("小白"));

        System.out.println();
    }

}

class Student2 {
    public void feedPet(IPet pet) {
        pet.beFriendly();
        pet.beAccompanied();
    }
}

//定义接口
interface IPet {
    void beFriendly();

    void beAccompanied();
}

//定义抽象类
abstract class Animal {
    private String name;

    //定义抽象方法
    public abstract void move();

    public Animal(String name) {
        super();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

//继承animal 实现IPet
class Cat extends Animal implements IPet {
    public Cat(String name) {
        super(name);
    }

    //实现beFriendly方法
    public void beFriendly() {
        System.out.println("i am 小白 cat, i am friendly");
    }

    //实现be beAccompanied方法
    public void beAccompanied() {
        System.out.print("i am 小白 cat, i can accompany you quiently");
    }

    @Override
    public void move() {
        // TODO Auto-generated method stub
        System.out.println("cat move quiently");
    }
}

//继承animal 实现IPet
class Dog extends Animal implements IPet {
    public Dog(String name) {
        super(name);
    }

    //实现beFriendly方法
    public void beFriendly() {
        System.out.println("i am 小汪 dog, i am friendly");
    }

    //实现be beAccompanied法
    public void beAccompanied() {
        System.out.println("i am 小汪 dog, i can talk a walk with you ");
    }

    @Override
    public void move() {
        // TODO Auto-generated method stub
        System.out.println("dog move quickly");
    }
}

